Home:ALL Converter>ignore :: Applicative f => f a -> f ()

ignore :: Applicative f => f a -> f ()

Ask Time:2020-03-10T08:55:46         Author:Tomer

Json Formatter

I need any function with this signature :

ignore :: Applicative f => f a -> f ()

Can someone point me to the right direction ?

Thanks!

Author:Tomer,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/60610252/ignore-applicative-f-f-a-f
MikaelF :

Like @Amadan said in the comments, you can easily find answers to this kind of questions by using the Hoogle search engine. Nevertheless, here are a few ways you can do this:\n\n\nYou can observe that what you need is a mapping to a constant value (()). In Haskell, that's const (). All you have to do now is modify this function so that it will affect the value inside an (applicative) functor. And what value makes a function into a function on functors? fmap. Put all of this together, and you get solution #1: fmap $ const ().\nThere's a function in the Prelude that takes a functor and replaces its value with another: (<$) :: Functor f => a -> f b -> f a. Here, a is (), so you get solution #2: () <$.\nUse Hoogle, and you get void from Data.Functor and Control.Monad. This function is also useful when you have a monadic action and want to ignore its result by switching it out with ().\nWrite it out the long-winded way with a lambda (as you did in the comments): ignore f = (\\_ -> ()) <$> f, or just ignore = fmap $ \\_ -> ()\n",
2020-03-10T02:14:58
yy